///
/// ArmyBodger 3
/// (c)2010 richyp
///
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ArmyBodger.Core {
    /// <summary>
    /// A Collection of Unit objects
    /// </summary>
    public class UnitCollection : List<Unit> {
        /// <summary>
        /// Get a collection of all Unit objects in this collection
        /// with the specified name
        /// </summary>
        /// <param name="name">The name of the Unit object to collect</param>
        /// <returns>A Collection of matching Unit objects</returns>
        public UnitCollection GetUnitsByName(String name) {
            UnitCollection results = new UnitCollection();
            foreach (Unit unit in this) {
                if (unit.Name == name) {
                    results.Add(unit);
                }
            }
            return results;
        }
        /// <summary>
        /// Copy this collection to a new instance
        /// </summary>
        /// <returns>
        /// A new UnitCollection object containing new instances of
        /// the unit objects
        /// </returns>
        public UnitCollection Copy() {
            return UnitCollection.Copy(this);
        }
        /// <summary>
        /// Static copy method that takes an instance of UnitCollection and
        /// copies it to a new UnitCollection
        /// </summary>
        /// <param name="source">The UnitCollection object to copy</param>
        /// <returns>
        /// A new instance of UnitCollection with new instances of
        /// unit objects
        /// </returns>
        public static UnitCollection Copy(UnitCollection source) {
            UnitCollection units = new UnitCollection();
            foreach (Unit unit in source) {
                units.Add(unit.Copy((Entry)null));
            }
            return units;
        }
    }  
}
